@echo off

setlocal

set version=Debug
set objname=IExampleExe
set tlbfile="%~dp0%version%\%objname%.tlb"

set clsid={F760952D-96C9-4e59-B3D6-30B0C54A4F84}
set regbase=HKLM\Software\Classes\CLSID\%clsid%

set alias=%objname%.object
set reg_alias_base=HKLM\Software\Classes\%alias%

set PATH=C:\Windows\Microsoft.NET\Framework\v4.0.30319;%PATH%

set keyexist=0
reg query %regbase% /ve > nul 2>&1
if %errorlevel% equ 0 set keyexist=1

set delfail=0
reg delete %regbase% /f > nul 2>&1
if %errorlevel% neq 0 set delfail=1

if %keyexist% equ 1 (
  if %delfail% equ 1 (
    echo Run this batch file as administrator!
    goto end
  )
)

set keyexist=0
reg query %reg_alias_base% /ve > nul 2>&1
if %errorlevel% equ 0 set keyexist=1

set delfail=0
reg delete %reg_alias_base% /f > nul 2>&1
if %errorlevel% neq 0 set delfail=1

if %keyexist% equ 1 (
  if %delfail% equ 1 (
    echo Run this batch file as administrator!
    goto end
  )
)

if not exist %tlbfile% (
  echo %tlbfile% does not exist!
  goto end
)

regtlibv12 -u %tlbfile% > nul 2>&1

if %errorlevel% equ 9009 (
  echo Please add regtlibv12 path to PATH environment
  goto end
)

echo DONE!

:end
endlocal
pause